package com.magic.smartcity.view.more.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.magic.smartcity.R
import com.magic.smartcity.beans.BusLineStopBean
import com.magic.smartcity.databinding.ItemBusHomeListStationListBinding

/**
 * @description:
 * @create: Create by Magic on 2022/2/23.
 */
class BusLineListStopListAdapter(data: List<BusLineStopBean>) :
    RecyclerView.Adapter<BusLineListStopListAdapter.ItemHolder>() {
    val data = data

    class ItemHolder(binding: ItemBusHomeListStationListBinding) :
        RecyclerView.ViewHolder(binding.root) {
        val binding = binding
    }

    private val TAG: String = "BusLineListStopListAdapter"
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        var inflate = DataBindingUtil.inflate<ItemBusHomeListStationListBinding>(
            LayoutInflater.from(parent.context),
            R.layout.item_bus_home_list_station_list,
            parent,
            false
        )
        return ItemHolder(inflate)
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        when (position) {
            0 -> {
                holder.binding.station.text = "起点: ${data[position].name}"
            }
            data.size-1->{
                holder.binding.station.text = "终点: ${data[position].name}"
            }
            else -> {
                holder.binding.station.text = "          ${data[position].name}"
            }
        }
    }

    override fun getItemCount() = data.size
}